package com.shujia.redisapi;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import javax.jws.soap.SOAPBinding;
import java.util.HashSet;

/*
    使用Jedis连接redis集群 7000~7006
 */
public class RedisDemo2 {
    public static void main(String[] args) {
        //public JedisCluster(Set<HostAndPort> nodes)
        //将集群中多个redis服务封装成一个Set集合
        //每一个redis服务封装成HostAndPort对象
        HashSet<HostAndPort> hostAndPorts = new HashSet<>();
        //public HostAndPort(String host, int port)
        hostAndPorts.add(new HostAndPort("192.168.21.150", 7000));
        hostAndPorts.add(new HostAndPort("192.168.21.150", 7001));
        hostAndPorts.add(new HostAndPort("192.168.21.150", 7002));
        hostAndPorts.add(new HostAndPort("192.168.21.150", 7003));
        hostAndPorts.add(new HostAndPort("192.168.21.150", 7004));
        hostAndPorts.add(new HostAndPort("192.168.21.150", 7005));
        hostAndPorts.add(new HostAndPort("192.168.21.150", 7006));

        JedisCluster jedisCluster = new JedisCluster(hostAndPorts);
        System.out.println("redis集群连接成功！！" + jedisCluster);

//        jedisCluster.set("age", "18");
//        jedisCluster.set("address", "安徽合肥");

        //删除的时候，只能一个一个删。
//        jedisCluster.del("age");
//        jedisCluster.del("address");
//        jedisCluster.del("name","namee"); //集群下是不允许的



        //关闭并释放连接资源
        jedisCluster.close();
    }
}
